﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Media.Imaging;
namespace WPFTest
{
    //TODO: Make it so that you select a folder and not a filename, so that you can use the path more cleanly
    public class Manager
    {
        List<Div> frames;

        public Manager()
        {
            //Initialize our List
            frames = new List<Div>();
        }

        public void AddImageDiv(BitmapSource bs)
        {
            DivImage d = new DivImage(bs,frames.Count);
            frames.Add(d);
        }

        public void AddImageTextDiv(BitmapSource bs, string text)
        {
            DivImage d = new DivImageText(bs, frames.Count, text);
            frames.Add(d);
        }

        public void GenerateHTML(string out_folder)
        {
            TextWriter tWriter = new StreamWriter(out_folder + "index.html");
            tWriter.WriteLine("<html>"); 
                tWriter.WriteLine("<head>");  
                        tWriter.WriteLine("<title>");
                            writeHtmlTitle(tWriter);
                        tWriter.WriteLine("</title>");
                        tWriter.WriteLine("<link href='stylesheet_default.css' rel='stylesheet' type='text/css' />");
                tWriter.WriteLine("</head>");
                tWriter.WriteLine("<body class='class_body'>");
                    tWriter.WriteLine("<div id ='class_main'>");
                        WriteHeader(tWriter);
                        //writeHtmlImageDivs(tWriter);
                        writeDivs(tWriter,out_folder);
                        WriteFooter(tWriter);
                    tWriter.WriteLine("</div>");
                tWriter.WriteLine("</body>");
            tWriter.WriteLine("</html>");
            tWriter.Close();
        }

        private void writeDivs(TextWriter tw, string out_path)
        {
            for (int i = 0; i < frames.Count; i++)
            {
                frames[i].WriteContent(tw, out_path);
            }
        }

        private void WriteHeader(TextWriter tWriter)
        {
            tWriter.WriteLine("<div id='header'>");
            tWriter.WriteLine("TODO");
            tWriter.WriteLine("</div>");
        }

        private void WriteFooter(TextWriter tWriter)
        {
            
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            System.Diagnostics.FileVersionInfo fInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
            string fileVersion = fInfo.ProductVersion;

            tWriter.WriteLine("<div id='footer'>");
            tWriter.WriteLine("Copyright OzTut Version:" + fileVersion);
            tWriter.WriteLine("</div>");
        }

        private void writeHtmlTitle(TextWriter tw)
        {
            tw.WriteLine("TODO");
        }

    }
}
